<?php
/**
 * Application Manager Controller (Admin version)
 *
 * Sewiki is a experimental software for course
 * Software Engineering in HIT and it's devoloped
 * upon CodeIgniter Framework. More infomation of
 * the framework, please vist http://codeigniter.com/
 *
 * @package  : CodeIgniter
 * @category : controller/admin
 * @author   : Oneplus <oneplus.lau@gmail.com>
 * @date     : 2011-06-18
 */
class ApplicationManager extends CI_Controller {
	/**
	 * The constructor
	 *
	 * @access : public
	 * @return : void
	 */
	function __construct() {
		parent::__construct();
		$this->load->database();
		$this->load->model('editorList');
		$this->load->model('application');
	}
	
	/**
	 * Method accept
	 *
	 * For Admin to accept the application with $aid
	 *
	 * @access : public
	 * @param  : $aid, int
	 * @return : void
	 */
	public function accept($aid) {
		// step i   get application infomation
		$application = $this->db->get_where('applications', array('aid' => $aid));
		$bid         = $application->row()->bid;
		$uid         = $application->row()->uid;
		
		$data = array(
			'bid' => $bid,
			'uid' => $uid);

		// step ii  insert user into the certain book's edit_list
		$this->editorList->createListItem($data);
		
		// step iii the application has been processed
		$data = array(
			'aid' => $aid);
		$this->application->deleteApplication($data);
		
		redirect('browser/browser/applicationList');
	}
	
	/**
	 * Method Decline 
	 *
	 * For Admin to decline the application with $aid
	 *
	 * @access : public
	 * @param  : $aid, int
	 * @return : void
	 */
	public function decline($aid) {
		// step i   the application has been processed
		$data = array('aid' => $aid);
		$this->application->deleteApplication($data);
		redirect('browser/browser/applicationList');
	}
}
?>